module.exports = function($scope, $state, $stateParams, $modalInstance, $resource,$modal,toaster, flag, item, type){
    $scope.maxSize = 5;             //最多显示多少个按钮
    $scope.bigCurrentPage = 1;      //当前页码
    $scope.itemsPerPage = 10 ;
    $scope.typelist = [];
    $scope.info = item;
    console.log($scope.info);
    console.log(type);
    $scope.type = type;
    $scope.getlist = function () {
        var para = {
            pageNo:$scope.bigCurrentPage, 
            pageSize:$scope.itemsPerPage,
        };
        para = angular.extend(para, $scope.searchform);
        $resource('/api/as/goc/viewAlevelIndexCategoryAd/findViewAlevelIndexList', {}, {}).
        save(para,function (res) {
            if (res.errcode != 0) {
                toaster.success({title:"",body:res.errmsg});
                return;
            }
            console.log(res);
            $scope.objs = res.data;
            $scope.bigTotalItems = res.data.totalRecord;  
            $scope.objs.forEach(function(element) {
                for(var i = 0; i < $scope.info.indexlist.length; i++){
                    if(element.index_id == $scope.info.indexlist[i]. index_id){
                    element.mark = true;
                    $scope.typelist.push($scope.info.indexlist[i]);
                    console.log('详情数组');
                    console.log($scope.typelist);
                    }
                }
            }, this);
                                                
        });        
    };
    $scope.getlist();
    $scope.change = function(obj){
        console.log(obj);
        // console.log($scope.typelist);
        if(obj.mark ==true){

            $scope.typelist.push(obj)
        }else{
            for(var i = 0;i<$scope.typelist.length;i++){
                if(obj.index_id == $scope.typelist[i].index_id){
                    $scope.typelist.splice(i,1);
                }
            }
        }
        console.log('下面是type、list');
        console.log($scope.typelist);
        $scope.info.indexlist = $scope.typelist;
    }
    $scope.ok = function() {
          $resource('/api/ac/goc/viewAlevelIndexCategoryService/createViewAlevelIndex', {}, {}).
            save($scope.info,  function (res) {
                if (res.errcode != 0) {
                    toaster.error({title:"",body:res.errmsg});
                    return;                      
                }     
                console.log(res);
                toaster.success({title:"",body:'操作成功'});     
                $modalInstance.close(); 
            });    
    }
    $scope.cancel = function(){
      $modalInstance.close(); 
    }
};